package com.xmxsuperstar.app.ttac.thread;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ListView;

import com.xmxsuperstar.app.ttc.client.ClientConstants;
import com.xmxsuperstar.app.ttc.client.TwitterTimeLineClient;

public abstract class TimeLineThread extends Thread {
	protected final Context context;
	protected final ListView lv;
	protected final Handler headImageHandler;
	protected final Handler timeLineHandler;
	protected final TwitterTimeLineClient tc;

	public TimeLineThread(Context context, ListView lv,
			Handler headImageHandler, Handler timeLineHandler,
			TwitterTimeLineClient tc) {
		this.context = context;
		this.lv = lv;
		this.headImageHandler = headImageHandler;
		this.timeLineHandler = timeLineHandler;
		this.tc = tc;
	}

	@Override
	public void run() {

		sendMsgBeforeGetData();
		getData();
		sendMsgAfterGetData();

	}

	protected void sendMsgBeforeGetData() {
		Message msg = new Message();
		msg.what = 0;

		Map<String, Object> map = new HashMap<String, Object>();

		map.put("context", context);

		msg.obj = map;

		timeLineHandler.sendMessage(msg);
		Log.i(ClientConstants.LogTag, "BeforeGetData msg send");
	}

	protected void sendMsgAfterGetData() {
		Message msg = new Message();
		msg.what = 1;

		Map<String, Object> map = new HashMap<String, Object>();

		map.put("listView", lv);
		map.put("context", context);
		map.put("headImageHandler", headImageHandler);

		msg.obj = map;
		timeLineHandler.sendMessage(msg);
		Log.i(ClientConstants.LogTag, "AfterGetData msg send");
	}

	abstract protected void getData();
}
